import { refreshPageNumberInHeader, refreshAnnexNumber } from '@/utils/dom'
import { refreshTableNumbers } from '@/utils/plugins/table/noteSetting'
import { refreshFigureNumbers } from '@/utils/plugins/image/figureSetting'

export default function (editor) {
  editor.on('pageAdd', () => {
    console.debug('---pageAdd---')
    refreshPageNumberInHeader(editor)
    refreshAnnexNumber(editor)
  })

  editor.on('pageRemove', () => {
    console.debug('---pageRemove---')
    refreshPageNumberInHeader(editor)
    refreshAnnexNumber(editor)
    // 删除章节，刷新正文的表格、图编号
    refreshTableNumbers(editor)
    refreshFigureNumbers(editor)
  })

  editor.on('pageUpdated', () => {
    console.debug('---pageUpdated---')
    refreshPageNumberInHeader(editor)
  })

  editor.on('contentPasted', () => {
    console.debug('---contentPasted---')
    refreshTableNumbers(editor)
    refreshFigureNumbers(editor)
  })
}
